const fs = require('fs')
const http = require('http')

http.createServer((req,res)=>{
	const {url , method, headers } = req
	if(url === '/' && method === 'GET'){
		fs.readFile('index.html', (err,data)=>{
			if(err){
				 res.writeHead(500,{
					 'Content-Type': 'text.plain'
				 })	 
				 res.end("500 server bad.")
				 return
			}
			res.statusCode = 200
			res.end(data)
		})
	}else if(method === 'GET' && headers.accept.indexOf('image/*') != -1){
		// fs.createReadStream('.'+url).pipe(res)
		// 报错什么鬼
		console.log(1)
	}
	else{
		res.statusCode = 400
		res.end("page lose")
	}
})
.listen(3000,()=>{
	console.log('Server run on 3000')
})
